package designPattern.creation5.Singleton.chapter17_singleton.chapter17_2;

public class Moon {
    private static Moon singleton;
    double radius;
    double distanceToEarth;

    private Moon() {
        singleton = this;
        radius = 1738;
        distanceToEarth = 363300;
    }

    //懒汉
    public static synchronized Moon getMoon() {   //这是一个同步方法
        if (singleton == null) {
            singleton = new Moon();
        }
        return singleton;
    }

    public String show() {
        String s = "月亮的半径是" + radius + "km,距地球是" + distanceToEarth + "km";
        return s;
    }
}